package com.example.haojiutao.controller.admin;

import com.example.haojiutao.common.Result;
import com.example.haojiutao.model.domain.Admin;
import com.example.haojiutao.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 管理员
 * @Author: wang_meiying
 * @CreateTime: 2024/1/27 19:25
 */

@Slf4j
@Controller
@RequestMapping("admin/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;


    /**
     * 获取管理员信息
     */
    //TODO 获取数据库信息
    @GetMapping("admin/info")//只支持get请求，若干通过post请求会返回405
    @ResponseBody
    public Result getAdminInfo(){
        //TODO 需要在登录后获取当前ID
        Integer AdminId = 22;
        Admin admin =adminService.selectById(AdminId);
        return Result.success("查询成功！",admin);

    }
//    GET查询
//    POST 增加
//    PUT 修改
//    DELETE 删除

    /*
     * @Description: TODO
     * @Author: wang_meiying
     * @CreateTime: 2024/1/27 19:26
     * @param: user
     * @return: java.lang.String
     */

    //    ctrl + i 重写方法
    @PostMapping("admin/post") //等于@RequestMapping(method =POST ,value ="/path" )
    public Result insert(@RequestBody Admin admin){

        log.info("新增管理员信息：{}",admin);

        return adminService.insert(admin);
    }
    /*
     * @Description: 修改管理员信息
     * @Author: wang_meiying
     * @CreateTime: 2024/1/27 19:27
     * @param: user
     * @return: com.example.cardemo.common.Result
     */
    @PutMapping("admin/put")
    public Result userInfoUpdate(@RequestBody Admin admin){
        log.info("修改管理员信息：{}",admin);
        Integer adminId = 122222;
        admin.setAdminId(adminId);
        return adminService.adminInfoUpdate(admin);

    }

    /*
     * @Description: 根据ID删除 物理删除，逻辑删除
     * @Author: wang_meiying
     * @CreateTime: 2024/1/27 19:27
     * @param: id
     * @return: cn.edu.nxu.music.common.Result
     */

    @DeleteMapping("admin/delete/{id}")
    public Result delete1(@PathVariable("id") Integer adminId ){

        return adminService.deleteById(adminId);
    }

    @GetMapping("admin/list")
    public Result list(Admin admin){
        log.info("列表查询 list{}",admin);
        // List<User> users = UserService.listByUser(user);
        return Result.success("查询成功");

    }
}
